<?php


class b2c_ctl_wap_opinions extends b2c_ctl_wap_common{  

    function __construct(&$app){
        parent::__construct($app);
      
        $shopname = app::get('wap')->getConf('wap.name');
        $this->shopname =$shopname;
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('樱淘社').'_'.$shopname;
            $this->keywords = app::get('b2c')->_('樱淘社').'_'.$shopname;
            $this->description = app::get('b2c')->_('樱淘社').'_'.$shopname;
        }
        $this->action = $this->_request->get_act_name();
        if(!$this->action) $this->action = 'index';
        $this->pagedata['res_url'] = $this->app->res_url;
        /** end **/
    }
    function index(){
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"getopinionslist");
        $input['data'] = array("type"=>'fancy');
        $fancy = $this->getApi($input);
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"getopinionslist");
        $input['data'] = array("type"=>'praise');
        $praise = $this->getApi($input);
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"getopinions");
        $attention = $this->getApi($input);
        $this->pagedata['fancy'] = $fancy['status'] ? $fancy['data'] : array();
        $this->pagedata['praise'] = $praise['status'] ? $praise['data'] : array();
        $this->pagedata['attention'] = $attention['status'] ? $attention['data'] : array();
        $this->page('wap/opinions/index.html');
    }
    function info(){
        $this->title =$this->title ? $this->title :  $this->title."樱淘社";
        $this->keywords = $this->keywords? $this->keywords :  $this->keywords."樱淘社";
        $this->description = $this->description ?$this->description :   $this->description."樱淘社";
        $opinions_id = $_REQUEST['opinions_id'];
        $input['method'] = array("file"=>"mobileapi_rpc_goods","action"=>"get_opinions_info");
        $input['data'] = array("opinions_id"=>$opinions_id);
        $opinions = $this->getApi($input);
        if(!$opinions['status'] || !$opinions['data']){
            
            $this->begin(array('app' => 'b2c','ctl' => 'wap_opinions', 'act'=>'index'));
            $this->end(false, app::get('b2c')->_('该推荐不存在'));
        }
        if($opinions['data']['comment'])foreach ($opinions['data']['comment'] as $k=>$val){
            $before = time() - strtotime($val['created']);
            $opinions['data']['comment'][$k]['created'] = $this->getBefore($before);
        }
        $this->pagedata['opinions'] = $opinions['data'];
//        微信分享
        $this->pagedata['title'] = $opinions['data']['goods_name'];
        $this->pagedata['desc'] = $opinions['data']['brief'];
        $this->pagedata['link'] = kernel::base_url(1).$this->gen_url(array('app'=>'b2c','ctl'=>'wap_opinions','act'=>'info'))."?opinions_id=".$opinions_id;
        $this->pagedata['imgUrl'] = $opinions['data']['image'];

        $this->page('wap/opinions/info.html');
    }
    function getBefore($time){
        if($time < 3600){
            return ceil($time/60)."分钟前";
        }
        if($time >= 3600 && $time <86400){
            return ceil($time/3600)."小时前";
        }
        if($time >= 86400 && $time <259200){
            return ceil($time/86400)."天前";
        }
        if($time >= 259200){
            return "一个月前";
        }
    }
}
